<?php

namespace app\index\controller;

use think\Config;
use think\Controller;
use think\Session;
use think\Db;
use app\common\controller\HomeBase;
use app\common\model\UserFollow as FollowModel;

class UserFollow extends HomeBase{
    
    protected $follow_model;
    protected function _initialize()
    {
        parent::_initialize();
      
        $this->follow_model = new FollowModel();
    }

    /*
    关注用户
    */
    public function follow($fid){
        // 查询是否存在关注记录         当前用户id  ['eq',$current_uid],
        $current_uid = session::get('index_id');
        $map = ['fid'=> $fid,'uid'=>$current_uid];
        // $is_follow = $this->follow_model->checkFollow($fid);
        $is_follow = $this->follow_model->where($map)->select();
        // print_r($is_follow);
        if(empty($is_follow)){
            // echo 'not follow';
            $map['create_time'] =  date('Y-m-d H:i:s');
            $op_follow = $this->follow_model->save($map);
            if($op_follow){
                return $this->thinkJsonCodeMsg($op_follow,200,'关注成功');
            }else{
                return $this->thinkJsonCodeMsg($op_follow,'201','关注失败');
            }
        }else{
            echo '已结关注了的,请刷新一下请求';
            // return json_encode($is_follow,JSON_UNESCAPED_UNICODE);
            
            
        }

    }

    public function t_time(){
        echo time();
              
    }

}